package com.xy.config;

import com.xy.controller.MyFirstInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.stereotype.Controller;
import org.springframework.validation.MessageCodesResolver;
import org.springframework.validation.Validator;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.view.script.ScriptTemplateViewResolver;

import java.util.List;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/4/10 21:56
 * @description
 */
// mvc 只扫描controller
// useDefaultFilters=false 禁用默认的过滤规则；
@ComponentScan(value = "com.xy",
        includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION,
                classes = Controller.class),
        useDefaultFilters = false)
@EnableWebMvc
public class AppConfig implements WebMvcConfigurer {
    //视图解析器
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/WEB-INF/views/", ".jsp");
        //registry.jsp("/WEB-INF/views/",".html");
    }

    // 静态资源访问
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    // 拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyFirstInterceptor()).addPathPatterns("/**");
    }
}
